#include <bits/stdc++.h>
using namespace std;
int t;
int n, k;
string str;

int main()
{
    cin >> t;
    while (t--)
    {
        long long int ret = 0;
        cin >> n >> k;
        cin >> str;
        for (int i = 0, j = 0; i < n;)
        {
            if (str[i] == 'L')
            {
                ret--;
                i++;
            }
            else
            {
                j = i;
                while (j < n && str[j] == str[i])
                    j++;
                int len = j - i;

                if (len >= 3)
                {
                    ret += k * (len - 2) + 2;
                }
                else
                {
                    ret += len;
                }
                i = j;
            }
        }
        cout << ret << endl;
    }

    return 0;
}